package middle;

import java.util.ArrayList;
import java.util.List;

public class Solution_797 {

    private List<List<Integer>> res = new ArrayList<>();

    public List<List<Integer>> allPathsSourceTarget(int[][] graph) {
        dps(new ArrayList<>(), graph, 0);
        return res;
    }

    private void dps(List<Integer> list, int[][] graph, int index) {
        if (index == (graph.length - 1)) {
            // 到目的地了
            List<Integer> temp = new ArrayList<>(list);
            temp.add(index);
            res.add(temp);
            return;
        }
        int[] array = graph[index];
        if (array.length==0) {
            return;
        }
        list.add(index);
        for (int next : array) {
            dps(list, graph, next);
        }
        list.remove(list.size() - 1);
    }

    public static void main(String[] args) {
        Solution_797 model = new Solution_797();
//        List<List<Integer>> list = model.allPathsSourceTarget(new int[][]{{1,2},{3},{3},{}});
//        List<List<Integer>> list = model.allPathsSourceTarget(new int[][]{{4,3,1},{3,2,4},{3},{4},{}});
        List<List<Integer>> list = model.allPathsSourceTarget(new int[][]{{}});
        for (List<Integer> integers : list) {
            System.out.println(integers);
        }

        System.out.println((16077 % 32) / 8);
        System.out.println(16077 % 8);
    }
}
